package org.wdm.beans;


import java.util.*;

/**
 *
 * @author iakopap
 */
public class Route implements Comparable {

    private static final double METERS_TO_MILES = 0.000621371192;

    //Short summary of the route
    private String summary;
    //Rectangle bounds of the route area
    private double northeastLatitude;
    private double northeastLongitude;
    private double southwestLatitude;
    private double southwestLongitude;
    //Total estimated distance of the route in meters
    private double distance;
    //Total estimated duration in seconds
    private int duration;
    
    private double criminalityScore;
    
    //Set of step points along the route path
    private List<Step> steps;

    public Route() {
        this.summary = "unknown";
        this.northeastLatitude = 0.0;
        this.northeastLongitude = 0.0;
        this.southwestLatitude = 0.0;
        this.southwestLongitude = 0.0;
        this.distance = 0;
        this.duration = 0;
        this.steps = new ArrayList<Step>();
    }

    /**
     * @return the summary
     */
    public String getSummary() {
        return summary;
    }

    /**
     * @param summary the summary to set
     */
    public void setSummary(String summary) {
        this.summary = summary;
    }

    /**
     * @return the northeastLatitude
     */
    public double getNortheastLatitude() {
        return northeastLatitude;
    }

    /**
     * @param northeastLatitude the northeastLatitude to set
     */
    public void setNortheastLatitude(double northeastLatitude) {
        this.northeastLatitude = northeastLatitude;
    }

    /**
     * @return the northeastLongitude
     */
    public double getNortheastLongitude() {
        return northeastLongitude;
    }

    /**
     * @param northeastLongitude the northeastLongitude to set
     */
    public void setNortheastLongitude(double northeastLongitude) {
        this.northeastLongitude = northeastLongitude;
    }

    /**
     * @return the southwestLatitude
     */
    public double getSouthwestLatitude() {
        return southwestLatitude;
    }

    /**
     * @param southwestLatitude the southwestLatitude to set
     */
    public void setSouthwestLatitude(double southwestLatitude) {
        this.southwestLatitude = southwestLatitude;
    }

    /**
     * @return the southwestLongitude
     */
    public double getSouthwestLongitude() {
        return southwestLongitude;
    }

    /**
     * @param southwestLongitude the southwestLongitude to set
     */
    public void setSouthwestLongitude(double southwestLongitude) {
        this.southwestLongitude = southwestLongitude;
    }

    /**
     * @return the distance
     */
    public double getDistance() {
        return distance;
    }

    /**
     * @param distance the distance to set
     */
    public void setDistance(double distance, String unit) {
        if(unit.equalsIgnoreCase("meters")) {
            this.distance = distance * METERS_TO_MILES;
        } else {
            this.distance = distance;
        }
    }

    public double getDistanceInMiles() {
        return distance * METERS_TO_MILES;
    }

    public void setDistanceInMiles(double miles) {
        this.distance = miles / METERS_TO_MILES;
    }
    
    public double getCriminalityScore() {
        return criminalityScore;
    }

    public void setCriminalityScore(double criminalityScore) {
        this.criminalityScore = criminalityScore;
    }

    /**
     * @return the duration
     */
    public int getDuration() {
        return duration;
    }

    /**
     * @param duration the duration to set
     */
    public void setDuration(int duration) {
        this.duration = duration;
    }

    public void addStep(Step step) {
        steps.add(step);
    }
    
    public void addSteps(List<Step> steps){
        this.steps.addAll(steps);
    }
    
    public List<Step> getSteps(){
        return steps;
    }
    
//    public void addCrimeToStep(int index, Crime crime){
//        //kati eksipno
//        if(steps.get(index).contains(crime.getCords())){
//            crimeCounter++;
//            steps.get(index).addCrime(crime);
//        }
//    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Route\n");
        sb.append(" Summary: ").append(summary).append("\n");
        sb.append(" Distance: ").append(distance).append("\n");
        sb.append(" Duration: ").append(duration).append("\n");
        sb.append(" NE: ").append("[").append(northeastLatitude).append(", ").append(northeastLongitude).append("]\n");
        sb.append(" SW: ").append("[").append(southwestLatitude).append(", ").append(southwestLongitude).append("]\n");
        sb.append(" Steps\n");
        for(Step step : steps){
            sb.append("\t").append(step).append("\n");
        }

        return sb.toString();
    }


    public void computeDistance(){
        for(Step step : steps){
            distance += step.getDistance();
        }
    }

    public int compareTo(Object o) {
        Route other = (Route) o;
        if(this.criminalityScore < other.getCriminalityScore()){
            return -1;
        } else if(this.criminalityScore > other.getCriminalityScore()){
            return 1;
        } else {
            return 0;
        }
//        Route other = (Route) o;
//        if(this.distance < other.getDistance()){
//            return -1;
//        } else if(this.distance > other.getDistance()){
//            return 1;
//        } else {
//            return 0;
//        }
    }
}
